package com.nutricia.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
//import java.util.ArrayList;
//import java.util.List;

/**
 * swgger2 配置
 *
 * @author: huangsheng
 * @date: 2018/4/16
 */
@Configuration
@EnableSwagger2
public class SwggerConfig {

    @Value("${swagger.basePackage}")
    private String swaggerBasePackage;

    @Bean
    public Docket createRestApi() {
        //添加head参数start
//        ParameterBuilder adminApiTokenPar = new ParameterBuilder();
//        ParameterBuilder apiTokenPar = new ParameterBuilder();
//        List<Parameter> pars = new ArrayList<>();
//        adminApiTokenPar.name("admin_api_token").description("System用户Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        apiTokenPar.name("api_token").description("前端会员Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        pars.add(adminApiTokenPar.build());
//        pars.add(apiTokenPar.build());
        //添加head参数end
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(swaggerBasePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .version("1.0")
                .build();
    }
}
